package croe.jdbc.dao.impl;

import croe.jdbc.dao.DataTypeConver;

import java.sql.Types;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * User: zengzhili
 * Time: 2014-07-05 17:26
 */
public class MySqlDataTypeConver implements DataTypeConver {

    private final static Map<Class, Integer> map = new HashMap<Class, Integer>();

    static {
        map.put(String.class, Types.VARCHAR);

        map.put(int.class, Types.INTEGER);
        map.put(Integer.class, Types.INTEGER);

        map.put(Float.class, Types.REAL);
        map.put(float.class, Types.REAL);

        map.put(long.class, Types.BIGINT);
        map.put(Long.class, Types.BIGINT);

        map.put(double.class, Types.DOUBLE);
        map.put(Double.class, Types.DOUBLE);

        map.put(Date.class, Types.TIMESTAMP);

        map.put(Byte.class, Types.TINYINT);
        map.put(byte.class, Types.TINYINT);

        map.put(short.class, Types.TINYINT);
        map.put(Short.class, Types.TINYINT);

        map.put(char.class, Types.CHAR);
        map.put(Character.class, Types.CHAR);

    }

    @Override
    public int[] conver(List<Class> classList) {
        int[] types = new int[classList.size()];
        int i = 0;
        for (Class clazz : classList) {
            types[i] = map.get(clazz);
            i++;
        }

        return types;
    }
}
